home *** CD-ROM | disk | FTP | other *** search
-
- { this unit performs graphics based text writes to the screen }
- { released to public domain 3/15/89 by author Michael Day}
- {for mouse support, enable the mouse unit in the uses statement}
- {and uncomment the HideMouse and ShowMouse procedures in this unit}
-
- unit AreaWr;
- interface
-
- uses graph,{mouse,}gstart;
-
- const
- LeftWrite = 0; {left justify text in box}
- CenterWrite = 1; {center text in box}
- RightWrite = 2; {right justify text in box}
- OffLeftWrite = 3; {left justify text with 1/2 char offset}
- OffRightWrite = 4; {right justify text with 1/2 char offset}
- PoffLeftWrite = 5; {left justify with one pixel offset}
- PoffRightWrite = 6; {right justify with one pixel offset}
-
- type
- ColorRec = record
- WritePos : byte; { left, center, or right}
- FColor : byte; { Foreground color }
- BColor : byte; { Background color }
- BPattern : byte; { Background pattern }
- end;
-
- const
- DummyColors : ColorRec = (WritePos : CenterWrite;
- FColor : white;
- BColor : black;
- BPattern : SolidFill);
-
- procedure SetColorRec(var C:ColorRec; WP,FC,BC,BP:word);
- procedure SetRect(var R:rect; x1,y1,x2,y2:integer);
- procedure AreaCharWrite(Ch:Char; R:rect; C:ColorRec; Pos,Wide:word);
- procedure AreaWrite(var Item:String; {string to be written}
- R:rect; {area to write it in}
- C:ColorRec); {colors and pattern to use}
- procedure AreaWritePos(R:rect; {area to write it in}
- Direction:word; {string print direction}
- Pos:word; {character to be written}
- Wide:word; {width of string space}
- var X,Y:integer; {Graphic position of char}
- var Len:integer); {max char position available}
-
-
- implementation
-
-
- {----------------------------------------------------------------}
- procedure SetColorRec(var C:ColorRec; WP,FC,BC,BP:word);
- begin
- C.WritePos := WP;
- C.FColor := FC;
- C.BColor := BC;
- C.BPattern := BP;
- end;
-
- {----------------------------------------------------------------}
- procedure SetRect(var R:rect; x1,y1,x2,y2:integer);
- begin
- R.Xmin := x1;
- R.Ymin := y1;
- R.Xmax := x2;
- R.Ymax := y2;
- end;
-
- {----------------------------------------------------------------}
- { draw a bar pattern on the screen - remember to save the mouse first! }
- { - this is ment for internal use - }
- procedure DrawCBar(Area:rect; Colors:ColorRec);
- begin
- with Area,Colors do
- begin
- SetFillStyle(BPattern,BColor);
- Bar(Xmin,Ymin,Xmax,Ymax);
- end;
- end;
-
-
- {----------------------------------------------------------------}
- {On entry Len contains the length of the string to be written}
- {Direction contains how the string is to be drawn, and R is the area}
- {On exit TMax is set to the maximum number of char that can be written}
- {sets X to the first position in the rectangle to draw a string}
-
- procedure SetAreaWrite(R:rect; Direction:integer; Len:integer;
- var X:integer; var TMax:integer);
- var LenMax : integer;
- begin
- TMax := (succ(R.Xmax-R.Xmin) div BoxTextWidth);
- if TMax < Len then LenMax := TMax else LenMax := Len;
- if LenMax < 1 then LenMax := 1;
-
- case Direction of
- CenterWrite :
- begin
- x := R.Xmin +
- succ((R.Xmax-R.Xmin) shr 1) - ((LenMax*BoxTextWidth) shr 1);
- end;
- RightWrite :
- begin
- x := R.Xmax - pred(LenMax*BoxTextWidth);
- end;
- OffLeftWrite :
- begin
- x := R.Xmin + 4;
- TMax := (succ(R.Xmax-x) div BoxTextWidth);
- end;
- OffRightWrite :
- begin
- TMax := (succ(R.Xmax-3-R.Xmin) div BoxTextWidth);
- if TMax < Len then LenMax := TMax else LenMax := Len;
- if LenMax < 1 then LenMax := 1;
- x := R.Xmax - 3 - (LenMax*BoxTextWidth);
- end;
- PoffLeftWrite :
- begin
- x := succ(R.Xmin);
- end;
- PoffRightWrite :
- begin
- x := R.Xmax - (LenMax*BoxTextWidth);
- end;
- else {LeftWrite}
- begin
- x := R.Xmin;
- end;
- end;
- end;
-
- {-----------------------------------------------------}
- {write the string starting at the left of the given rectangle}
- procedure AreaWrite(var Item:String; {string to be written}
- R:rect; {area to write it in}
- C:ColorRec); {colors and pattern to use}
- var x,y: integer;
- Len:integer;
- begin
- SetAreaWrite(R,C.WritePos,length(Item),X,Len);
- y := ((R.Ymax-R.Ymin) shr 1) + succ(R.Ymin);
- { HideMouse; }
- SetTextJustify(LeftText,CenterText);
- DrawCBar(R,C);
- moveto(x,y);
- setcolor(C.FColor);
- outtext(copy(Item,1,Len));
- { ShowMouse; }
- end;
-
-
- {-----------------------------------------------------}
- {on entry Width contains the string length that is to be written,}
- {Pos contains the character position in the string that XY is to}
- {point to. R is the area to place the string in, and Direction is}
- {the way the string is to be written. On exit X,Y has the screen}
- {position of the character specified in Pos. Based on the top left}
- {corner of the character cell. Len indicates the largest possible}
- {string that can be written in the area.}
-
- procedure AreaWritePos(R:rect; {area to write it in}
- Direction:word; {string print direction}
- Pos:word; {character to be written}
- Wide:word; {width of string space}
- var X,Y:integer; {Graphic position of char}
- var Len:integer); {max char position available}
- begin
- SetAreaWrite(R,Direction,Wide,X,Len); {get first char screen X loc}
- if Len > 0 then
- begin
- if (Len < Pos) or (Pos < 1) then
- X := X + (pred(Len)*BoxTextWidth)
- else
- X := X + (pred(Pos)*BoxTextWidth);
- end;
- if (X+pred(BoxTextWidth)) > R.Xmax then X := X-BoxTextWidth;
- Y := R.Ymin;
- end;
-
-
- {-----------------------------------------------------}
- {write a character on the screen at Pos}
- procedure AreaCharWrite(Ch:Char; R:rect; C:ColorRec; Pos,Wide:word);
- var X,Y,Len:integer;
- begin
- AreaWritePos(R,C.WritePos,Pos,Wide,X,Y,Len);
- y := ((R.Ymax-R.Ymin) shr 1) + succ(R.Ymin);
- { HideMouse; }
- SetTextJustify(LeftText,CenterText);
- SetFillStyle(C.BPattern,C.BColor);
- bar(X,R.Ymin,X+pred(BoxTextWidth),R.Ymax);
- moveto(x,y);
- setcolor(C.FColor);
- outtext(Ch);
- { ShowMouse; }
- end;
-
- {-----------------------------------------------------}
- {returns the maximum number of characters that can be }
- {written in a rectangle }
-
- function GetMaxAreaSize(R:rect):word;
- begin
- GetMaxAreaSize := succ(R.Xmax-R.Xmin) div BoxTextWidth;
- end;
-
-
- {----------------}
- {no init needed}
-
- end.
-